package com.jqq.string_;

import java.util.Scanner;

/**
 * @author 姬倩倩
 * @version 1.0
 */
public class StringBufferExercise {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        StringBuffer sb = new StringBuffer();
        StringBuffer sb1 = new StringBuffer();
        System.out.println("请输入商品名");
        sb1.append(scanner.next());
        System.out.println("请输入商品价格");
        sb.append(scanner.next());
        //[dotIndex-1 - 0]  每3位前插入 ,
        // 即在i-3位插入，要保证不在第一位插入 i-3>0
        for (int i = sb.indexOf("."); i-3 > 0; i -= 3) {
            sb.insert(i-3, ',');
        }

        //引入变量j，记录往前走的步数
        for (int i = sb.indexOf("."), j = 1; i > 0; i--, j++) {
            if (j % 3 == 0) {
                sb.insert(i, ',');
            }
        }
        System.out.println("商品名称\t\t商品价格");
        System.out.println(sb1.toString() + "\t\t" + sb.toString());

    }
}
